#! /bin/sh
# PSdemo1 - simple example script for sufdmod1, PostScript graphics
# N. Maercklin, Oct. 2006

# Output file names (velocity,density and seismogram):
vfile=velocity.bin
dfile=density.bin
sufile=seismogram.su

# Output PostScript file (three plots on one page):
psfile=demo.ps

# Velocity and density model:
depth=0,600,601,1200,1201,1500,1501,2000
velo=2000,2000,3000,3000,2600,2600,4500,4500
dens=1.5,1.5,2.0,2.0,2.0,2.0,2.6,2.6
nz=2001
dz=1

# Modelling parameters:
sz=1       # source depth
rz=1       # receiver depth
tmax=1.5   # max. time of seismogram
styp=1     # source type (0, 1, or 2)
abs=1,1    # boundary conditions

# Program to view PostScript files on screen:
PSPREVIEW=gv

# Make models:
unisam xin=$depth yin=$velo dxout=$dz nout=$nz > $vfile
unisam xin=$depth yin=$dens dxout=$dz nout=$nz > $dfile

# PostScript plot of velocity model:
psgraph <$vfile n=$nz d1=$dz pairs=0 x2beg=1000 x2end=5000 \
    d2num=1000 n2tic=2 d1num=500 n1tic=5 style=seismic \
    label1="depth (m)" label2="velocity (m/s)" linecolor=red \
    title="velocity model" wbox=4 hbox=5 >${vfile}.ps


# PostScript plot of density model:
psgraph <$dfile n=$nz d1=$dz pairs=0 x2beg=1.0 x2end=3.0 \
    d2num=0.5 n2tic=5 d1num=500 n1tic=5 style=seismic \
    label1="depth (m)" label2="density (g/cm3)" linecolor=green \
    title="density model" wbox=4 hbox=5 >${dfile}.ps


# Make seismogram:
sufdmod1 <$vfile nz=$nz dz=$dz sz=$sz rz=$rz tmax=$tmax \
    abs=$abs styp=$styp dfile=$dfile >$sufile

# Show seismogram:
supsgraph <$sufile label1="time (s)" linecolor=blue \
    title="seismogram" d1num=0.2 n1tic=2 wbox=4 hbox=5 >${sufile}.ps

# Merge the three PostScript plots onto one page:
$CWPROOT/bin/psmerge \
    in=${vfile}.ps  scale=0.7,0.7 translate=0.0,4.5 \
    in=${dfile}.ps  scale=0.7,0.7 translate=4.0,4.5 \
    in=${sufile}.ps scale=0.7,0.7 translate=0.0,0.0 > $psfile


# Echo output file names to stderr:
cat <<EOF 1>&2
${0}: Output files:
    Velocity model: $vfile (PS plot: ${vfile}.ps)
    Density model : $dfile (PS plot: ${dfile}.ps)
    Seismogram    : $sufile (PS plot: ${sufile}.ps)
    PS file (3 plots): $psfile
EOF


# View merged PostScript file on screen:
if [ -x `which $PSPREVIEW` ]; then
    $PSPREVIEW $psfile &
fi

exit 0
